package Demo;
import javax.swing.*;

import java.awt.Color;
import java.awt.Graphics;

public class BT4_Thread1 extends Thread{
	JPanel canvas;
	public BT4_Thread1(JPanel c){
		canvas = c;
	}
	public void run(){
		int width = canvas.getSize().width;
		int height = canvas.getSize().height;
		while(true){
			Graphics g = canvas.getGraphics();
			Color c = new Color((int)(255.0*Math.random()),
								(int)(255.0*Math.random()),
								(int)(255.0*Math.random()));
			g.setColor(c);
			
			for(int i=0; i<width/2;i++) {
				g.drawLine(i,0,i,(int)height);
				try{
					Thread.sleep(10);
				}
				catch(InterruptedException e){}
			}
			c = new Color((int)(255.0*Math.random()),
					(int)(255.0*Math.random()),
					(int)(255.0*Math.random()));
			g.setColor(c);
			for(int i = width/2; i>0 ;i--) {
				g.drawLine(i,height,i,0);
				try{
					Thread.sleep(10);
				}
				catch(InterruptedException e){}
			}
		}
	}
	
}
